import requests
API_URL = 'https://imgcode.toolshu.com/api'  # 接口地址
TOKEN = 'ts_BVZMYPZF1JBIGMKQJB0ECIVZQ'  # 替换为自己的token
def imgcode_file(imgpath):
    """
    本地图片识别
    :param imgpath: 本地图片路径
    :return: 识别结果
    """
    data = {
        'token': TOKEN,
    }
    # binary上传文件
    files = {'file': open(imgpath, 'rb')}

    response = requests.post(API_URL, files=files, data=data)
    result = response.json()
    if result['success'] is True:
        return result['data']
    else:
        return 'error' 
    

